package cn.pxs.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;

@Configuration
@EnableResourceServer
public class MyResourceServerConfig
    extends ResourceServerConfigurerAdapter {
    //管理 权限
    @Override
    public void configure(HttpSecurity http) throws Exception {
        http.requestMatchers().antMatchers("/api/**")
                .and()
                .authorizeRequests()
                .antMatchers("/api/adm/**").hasAuthority("G")//要身份为G的
                .antMatchers("/api/fore/**").hasAuthority("P")//要身份为P的
                .antMatchers("/api/public/**").permitAll()// public下的不需要登录即可
                .anyRequest().authenticated();//其余的需要登录后才可操作
    }
}
